<?php
/**
 *@author Connor <caokang@foxmail.com>
 *@todo
 *@link www.zeevin.com
 */
class Black extends CActiveRecord{
	const PAGE_SIZE=36;
	public static function model($className=__CLASS__){
		return parent::model($className);
	}

	public function tableName(){
		return 'user_blacklist';
	}

	public static function addBlack($bid){
		$b_tmp = Black::model()->findByAttributes(array('uid'=>Yii::app()->user->id,'bid'=>$bid));
		if($b_tmp)return array('status'=>0,'desc'=>'添加黑名单成功');
		$black = new Black('create');
		$black->uid = Yii::app()->user->id;
		$black->bid = $bid;
		$black->ctime = date('Y-m-d H:i:s');
		if($black->save()){
			$msg['status']=0;
			$msg['desc']='添加黑名单成功';
		}else{
			$msg['status']=1;
			$msg['desc']='拉黑失败';
		}
		return $msg;
	}
	public static function getList($status=3){
		$uid = Yii::app()->user->id;
		$condition .= " uid=:uid ";
		$params['uid']=Yii::app()->user->id;
		$criteria=new CDbCriteria();
	

		$criteria->condition = $condition;
		$criteria->params = $params;
		$criteria->select = 'id,uid,bid,ctime';
		$criteria->order = 'id DESC';
    	$count=Black::model()->count($criteria);
    	$pages=new CPagination($count);

    	// results per page
   	 	$pages->pageSize=self::PAGE_SIZE;
    	$pages->applyLimit($criteria);
    	$rs['total_num'] = $count;
    	$rs['rows'] = Black::model()->findAll($criteria);
    	$rs['pages'] = $pages;
    	return $rs;
  }
}